function [varargout] = get_infoAWQ(varargin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% RETURNS INFORMATIONS ABOUT AWQ SITES. 
%           
% OPTIONAL ARGUMENT: 
%               - 'chksite','sitenm' : name of AWQ site (string) ;
%                                      returns an error if sitename
%                                      doesn't exist                                             
%               - 'pos','sitenm'     : name of AWQ site (string) ;returns 
%                                      site longitude and latitude  
%               - 'list'             : returns the list of AWQ site
%                                      names
%               - 'all'              : returns the list of AWQ site names  
%                                      and positions  
%
% EXAMPLES:- get_infoAWQ('chksite,'B3')
%          - [lon,lat] = get_infoAWQ('pos','B3')
%          - [names] = get_infoAWQ('list')
%          - [names,lon,lat] = get_infoAWQ('all')
%
% Author: Benedicte Pasquer, IMOS/eMII (http://imos.org.au/)
% email: benedicte.pasquer@utas.edu.au
% May 2013   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%READS IN INFO FROM A FILE LISTING ALL AWQ SITE NAMES AND POSITIONS
opt = {'chksite','sitenm','pos','list','all'};
if ~any(strcmp(varargin{1},opt)), error ('Unknown option. Available options are: chksite, sitenm, pos, list, all'),end

currentdir = pwd;
fid = fopen(fullfile(currentdir,'AWQsiteconvert.txt'));
AWQpos = textscan(fid,'%s %d %d %9.5f %9.5f',29);
fclose(fid);

if length(varargin) > 2,error('Too many arguments'),end
switch varargin{1}
    case 'chksite'
        ind = strcmp(varargin{2},AWQpos{1});
        if isempty(ind)
            error('Unknown AWQ site name')
        end
    case 'pos'
        ind = strcmp(varargin{2},AWQpos{1});
   
        ind = find(ind==1);
        lat  = AWQpos{4}(ind);
        lon  = AWQpos{5}(ind);
        varargout = {lon;lat};
        
    case 'list'
        varargout = AWQpos(1);
        
    case 'all'
        name = AWQpos{1};
        lon = AWQpos{5};
        lat = AWQpos{4};
        varargout={name;lon;lat};
 end
        
            